package com.java110.mall.shop.bmo.shopSettingKey.impl;

import com.java110.mall.shop.bmo.shopSettingKey.IGetShopSettingKeyBMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import com.java110.intf.shop.IShopSettingKeyInnerServiceSMO;
import com.java110.dto.shop.ShopSettingKeyDto;
import org.springframework.http.HttpStatus;

import java.util.ArrayList;
import java.util.List;

@Service("getShopSettingKeyBMOImpl")
public class GetShopSettingKeyBMOImpl implements IGetShopSettingKeyBMO {

    @Autowired
    private IShopSettingKeyInnerServiceSMO shopSettingKeyInnerServiceSMOImpl;

    /**
     *
     *
     * @param  shopSettingKeyDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(ShopSettingKeyDto shopSettingKeyDto) {


        int count = shopSettingKeyInnerServiceSMOImpl.queryShopSettingKeysCount(shopSettingKeyDto);

        List<ShopSettingKeyDto> shopSettingKeyDtos = null;
        if (count > 0) {
            shopSettingKeyDtos = shopSettingKeyInnerServiceSMOImpl.queryShopSettingKeys(shopSettingKeyDto);
        } else {
            shopSettingKeyDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) shopSettingKeyDto.getRow()), count, shopSettingKeyDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
